# -*- coding: utf-8 -*-

from odoo import models, fields, api


class SaleOrder(models.Model):
    _inherit = 'sale.order'
    boat_location_id=fields.Many2one('stock.location',domain=[('usage','=','internal')],string=u'船号')
    boat_partner_ids=fields.One2many('res.partner',related='boat_location_id.boat_partner_ids',string='矿名')

    product_count=fields.Float(compute='compute_product_count',string=u'总数量')
    def compute_product_count(self):
        for r  in self:
            r.product_count=sum(line.product_uom_qty for line in r.order_line)



class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'
    boat_location_id = fields.Many2one('stock.location', related='order_id.boat_location_id', store=True,string=u'船号')
    small_boat_id=fields.Many2one('rjss.boat',string=u'小船')
    owner=fields.Char(related='small_boat_id.owner',string='船主',readonly=True)
    phone=fields.Char(related='small_boat_id.phone',string='电话',readonly=True)
    p_description=fields.Text(related='product_id.description',string='规格',readonly=True)
    date_order=fields.Datetime(related='order_id.date_order',readonly=True)


    bd_weight=fields.Float(string=u'磅单吨位')
    yh_weight=fields.Float(string=u'优惠吨位',compute='compute_yh_weight')
    @api.depends('bd_weight','product_uom_qty')
    def compute_yh_weight(self):
        for r in self:
            r.yh_weight=r.bd_weight-r.product_uom_qty
